﻿using System;
using System.Collections.Generic;
using ESRI.ArcGIS.Client.Async;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ArcGIS.Client.Tasks.Async.Tests
{
    [TestClass]
    public class ArcGISWebClientTests : SilverlightTest
    {
        [TestMethod, Asynchronous]
        [Description("http://resources.arcgis.com/en/help/silverlight-api/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ArcGISWebClient~DownloadStringAsync.html")]
        public async void DownloadString()
        {
            var webClient = new ESRI.ArcGIS.Client.ArcGISWebClient { DisableClientCaching = true };

            var myParameters = new Dictionary<string, string>
            {
                { "where", "POP2000 > 10000000" },
                { "returnGeometry", "false" },
                { "outFields", "*" },
                { "f", "pjson" }
            };
            
            var result = await webClient.DownloadStringTaskAsync(
                new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5/query"),
                myParameters);

            Assert.IsFalse(string.IsNullOrWhiteSpace(result));
            TestComplete();
        }
    }
}
